以下為「 Docker 安裝 MySQL 」影片中,使用到的文件內容。
除了安裝步驟還會介紹 Docker 是什麼 ? 以及為什麼要使用 Docker !
學會後,以後資料庫的安裝,都可以向 Python 的 pip 一樣,一行指令,動作直接完成 !
https://hub.docker.com/_/mysql
docker pull mysql:8
docker images
docker images | grep mysql
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8 0716d6ebcc1a 10 days ago 514MB
docker rmi ${IMAGE ID}
docker rmi 0716d6ebcc1a
docker run --name sql2 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=Dev127336 -d mysql:8
參數功能:
docker ps
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
925859fd62b1 mysql:8 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp sql2
docker stop sql2
docker ps -a
Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
115863d85607 mysql:8 "docker-entrypoint.s…" 24 seconds ago Exited (137) 2 seconds ago sql2
docker start sql2
docker exec -it sql2 bash
exit
docker rm sql2
進入到 Linux 的操作環境
docker exec -it sql2 bash
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Dev127336';
CREATE USER 'DevAuth'@'%' IDENTIFIED WITH mysql_native_password BY 'Dev127336';
GRANT ALL PRIVILEGES ON *.* TO 'DevAuth'@'%';
資料庫
create database DevDb; -- 創建資料庫
show databases; -- 顯示資料庫
use DevDb; -- 使用資料庫
資料表
創建:
drop table if exists app_info;
create table app_info (
id int auto_increment primary key ,
name nvarchar(50),
version nvarchar(30),
author nvarchar(50),
remark nvarchar(100)
);
資料:
insert into app_info(name,version,author,remark) values
('JavaProjSE-v1.0.3','1.0.3','Enoxs','Java Project Simple Example - Version 1.0.3'),
('JUnitSE','1.0.2','Enoxs', 'Java Unit Test Simple Example'),
('SpringMVC-SE','1.0.2','Enoxs','Java Web Application Spring MVC - Simple Example (MyBatis)');
查詢:
select * from app_info;
quit
exit
https://www.mysql.com/products/connector/